package com.eonmind.ai.mapper;

import com.eonmind.common.contract.data.base.BaseMongoMapper;
import com.eonmind.common.provider.entity.ai.ChatMessage;
import com.mongoplus.aggregate.Aggregate;
import com.mongoplus.aggregate.AggregateWrapper;
import com.mongoplus.conditions.query.LambdaQueryChainWrapper;
import com.mongoplus.conditions.query.QueryChainWrapper;
import com.mongoplus.conditions.query.QueryWrapper;
import com.mongoplus.mapper.MongoMapper;
import com.mongoplus.mapper.MongoMapperImpl;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ChatMessageMapper extends BaseMongoMapper<ChatMessage> {

    public List<ChatMessage> selectByConversationIdAndLimit(String conversationId, int lastN) {
        QueryWrapper<ChatMessage> eq = createMgoQuery()
                .eq(ChatMessage.Fields.conversationId, conversationId)
                .orderByAsc(ChatMessage.Fields.createTime);
        AggregateWrapper limit = new AggregateWrapper().match(eq).limit(lastN);
        return aggregateList(limit);
    }


}
